use Data_replication.dta

***********************************
*****DESCRIPTIVE STATISTICS********
***********************************

global covar age gender university unemployed i.bills soc_stat ethics 


dtable $covar, by(treatment) column(by(hide))

encode id, gen (idn)
xtset idn round
by idn (round), sort: gen diff_SR1= SR1_[round+1]- SR1_[round]
by idn (round), sort: gen diff_SR2= SR2_[round+1]- SR2_[round]
save "C:\Users\ivapa\OneDrive - London School of Economics\Social preferences and bribery\Data\combined_feb.dta", replace


summ $covar if round==1
summ charities* if round==1

* SELF treatment
summ $covar if round==1 & treatment==1

* patient treatment
summ $covar if round==1 & treatment==3

* test 
foreach v in $covar {
ttest `v', by(treatment)
ranksum `v', by(treatment)
} 
*
gen inequality_ratio=SR1_/SR2_


drop used_health* survey_treat bribe* neutral* q116* q126*

save "C:\Users\ivapa\OneDrive - London School of Economics\Social preferences and bribery\Data\favoritism.dta", replace

reshape wide SR* diff_SR* simple_diff* inequality_ratio fav_, i(idn) j(round)

gen punish_0=.
replace punish_0=1 if SR1_0==1
replace punish_0=0 if SR1_0!=1
gen punish_1=.
replace punish_1=1 if SR1_1==1
replace punish_1=0 if SR1_1!=1


save "C:\Users\ivapa\OneDrive - London School of Economics\Social preferences and bribery\Data\favoritism_wide.dta", replace
***Regression***

foreach x in punish_1 fav_1 inequality_ratio1{

reg `x' treat_dummy2 treat_dummy3 if treatment==1 |treatment==2 | treatment==3, vce(rob)
est store `x'_ineq
}
esttab punish_1_ineq fav_1_ineq ineq_1_ineq using ineq_output.csv, replace


foreach x in punish_1 fav_1 inequality_ratio1{

reg `x' treat_dummy4 if treatment==1 |treatment==4, vce(rob)
est store `x'_reject
}
esttab punish_1_reject fav_1_reject inequality_ratio1_reject using reject_output.csv, replace

qui reg fav_1 i.treatment if high_norm==0 & treatment==1|treatment==2|treatment==3, vce(robust)
eststo fav_low_norm
qui reg fav_1 i.treatment if high_norm==1 & treatment==1|treatment==2|treatment==3, vce(robust)
eststo fav_high_norm
qui reg inequality_ratio1 i.treatment if high_norm==0 & treatment==1|treatment==2|treatment==3, vce(robust)
eststo ineq_low_norm
qui reg inequality_ratio1 i.treatment if high_norm==1 & treatment==1|treatment==2|treatment==3, vce(robust)
eststo ineq_high_norm
qui reg punish_1 i.treatment if high_norm==0 & treatment==1|treatment==2|treatment==3, vce(robust)
eststo punish_low_norm
qui reg punish_1 i.treatment if high_norm==1 & treatment==1|treatment==2|treatment==3, vce(robust)
eststo punish_high_norm
esttab fav_low_norm fav_high_norm ineq_low_norm ineq_high_norm punish_low_norm punish_high_norm using norm_regressions.csv, cells("b(fmt(4))" se(par(`"("' `")"') fmt(4)) p(par(`"["' `"]"') fmt(4)))
reg fav_1 i.high_norm, vce(rob)
eststo norm_fav
reg inequality_ratio1 i.high_norm, vce(rob)
eststo norm_ineq
reg punish_1 i.high_norm, vce(rob)
eststo norm_punish
esttab norm_ineq norm_fav norm_punish using norm_output.csv